package com.caifu.bean;

import static com.caifu.bean.ResultEnum.UNKNOWN_ERROR;

/**
 * @Auther: Lyf
 * @Date: 2020/7/2 13:30
 * @Description:
 */
public class ResultUtil {

    public static Result success(String type, Object object) {
        Result result = new Result();
        if ("data".equals(type)) {
            result.setCode(ResultEnum.GETDATASUCCESS.getCode());
            result.setMsg(ResultEnum.GETDATASUCCESS.getMsg());
        } else {
            result.setCode(ResultEnum.SUCCESS.getCode());
            result.setMsg(ResultEnum.SUCCESS.getMsg());
        }
        result.setData(object);
        return result;
    }

    public static Result<Object> success() {
        Result<Object> result = new Result<>();
        result.setCode(ResultEnum.SUCCESS.getCode());
        result.setMsg(ResultEnum.SUCCESS.getMsg());
        return result;
    }

    public static Result<Object> getDataSuccess(Object object) {
        Result<Object> result = new Result<>();
        result.setCode(ResultEnum.GETDATASUCCESS.getCode());
        result.setMsg(ResultEnum.GETDATASUCCESS.getMsg());
        result.setData(object);
        return result;
    }

    public static Result success(String type) {
        if ("data".equals(type)) {
            return getDataSuccess(null);
        } else {
            return success();
        }
    }

    public static Result<Object> success(Integer code, String msg, Object data, int count) {
        Result<Object> result = new Result<>();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        result.setCount(count);
        return result;
    }

    public static Result<Object> success(Integer code, String msg, Object data) {
        Result<Object> result = new Result<>();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static Result<Object> success(Integer code, String msg) {
        Result<Object> result = new Result<>();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public static Result error(Integer code, String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public static Result<Object> error() {
        Result<Object> result = new Result<>();
        result.setCode(UNKNOWN_ERROR.getCode());
        result.setMsg(UNKNOWN_ERROR.getMsg());
        return result;
    }

    public static Result<Object> errorMsg(String msg) {
        Result<Object> result = new Result<>();
        result.setCode(ResultEnum.ERROR.getCode());
        result.setMsg(msg);
        return result;
    }

    public static Result retLog(Integer code, String msg, Object data) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static Result<Object> getPageDataSuccess(Object object) {
        Result<Object> result = new Result<>();
        result.setCode(ResultEnum.PAGE_LIST.getCode());
        result.setMsg(ResultEnum.PAGE_LIST.getMsg());
        result.setData(object);
        return result;
    }

}
